package com.kgc.app.controller;

import com.github.pagehelper.PageInfo;
import com.kgc.app.condition.AppInfoCondition;
import com.kgc.app.constants.AppConstant;
import com.kgc.app.dto.AppInfoDto;
import com.kgc.app.dto.AppVersionDto;
import com.kgc.app.pojo.AppInfo;
import com.kgc.app.pojo.AppVersion;
import com.kgc.app.service.AppInfoService;
import com.kgc.app.service.AppVersionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/backend/appinfo")
public class BackAppInfoController {

    //引入Appinfoservice层对象
    @Autowired
    private AppInfoService appInfoService;

    //引入APP版本对象的业务层对象
    @Autowired
    private AppVersionService appVersionService;

    @RequestMapping("/list")
    public String list(AppInfoCondition appInfoCondition, Model model){

        appInfoCondition.setDevId(AppConstant.STATIC_NO);

        appInfoCondition.setStatus(AppConstant.STATIC_NO);

        PageInfo<AppInfoDto> appInfoDtoPageInfo = appInfoService.selectAppInfoByCondition(appInfoCondition);

        model.addAttribute("appInfoList",appInfoDtoPageInfo);

        return "backend/applist";
    }

    @RequestMapping("/selectAppinfoAndVersion/{id}")
    public String selectAppinfoAndVersion(@PathVariable Long id,Model model){
        System.out.println(id);

        AppInfoDto appInfoDto = appInfoService.selectAppInfoDtoById(id);

        AppVersion appVersion = appVersionService.selectAppVersionById(appInfoDto.getVersionId());

        model.addAttribute("appInfo",appInfoDto);
        model.addAttribute("appVersion",appVersion);
        return "/backend/appcheck";

    }

    @RequestMapping("/checksave")
    public String checksave(AppInfo appInfo){

        appInfoService.updateAppInfo(appInfo);


        return "redirect:/backend/appinfo/list";
    }
}
